# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import re
import json

tmp_f = open(sys.argv[1], 'r')
res_f = open(sys.argv[2], 'r+')
cnt_f = open(sys.argv[3], 'r+');
cnt = int(cnt_f.read())
tmp = json.loads(tmp_f.read())
if (cnt > 0):
    res_f.seek(-1, 2)
    res_f.write("," + json.dumps(tmp)[1:])
else:
    res_f.seek(-2, 2)
    res_f.write(json.dumps(tmp)[1:])
tmp_f.close()
res_f.close()
cnt += len(tmp);
cnt_f.seek(0)
cnt_f.write(str(cnt))
print "all: " + str(cnt) + " ( +" + str(len(tmp)) + " )"
